<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>xx广场会员卡积分查询</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="format-detection" content="telephone=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="alternate icon" type="image/png" href="assets/i/favicon.png">
  <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
   <script type="text/javascript" src="js/ajax.js"></script> <!-- 载入 Ajax 类库 --> 
  <style>
    .header {
      text-align: center;
    }
    .header h1 {
      font-size: 200%;
      color: #333;
      margin-top: 30px;
    }
    .header p {
      font-size: 14px;
    }
  </style>
</head>
<body>


 <div class="header">
  <div class="am-g">
    <?php
error_reporting(0);
$openid='oDExxxxxxx_aaaaaa-Um63NecJ5o';//取得openid
//查询数据库判断是否绑定数据库密码55750596
//如果查询结果为空则出现绑定界面
//mysql数据库设置
$con = mysql_connect('localhost', 'root', 'root');
//mssql数据库设置
$conInfo=array('Database'=>'DBNAME', 'UID'=>'sa', 'PWD'=>'sa');
$server='sql server IP地址';
$conn=sqlsrv_connect($server, $conInfo);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("hy_user", $con);

$sql="SELECT hy_vip FROM hy_wx_vip WHERE openid = '".$openid."'";

$result = mysql_query($sql);
if (mysql_num_rows($result) < 1) { 
echo '<h1>会员卡绑定</h1>    <p>您还没有绑定，请绑定会员卡！</p>';?>
  </div>
  <hr />
</div> 
 
<div class="am-g">
  <div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
    
    <form action="insert.php" method="post" class="am-form">
      <label for="hy_vip">会员卡:</label>
	  <input  type="text" name="hy_vip" onBlur="validate(this.value);" class="" id="doc-ipt-email-1" placeholder="输入会员卡号" /><span id="userText"></span><br><!--查询系统中会员卡是否存在-->
      <input name="openid" value="<?php echo $openid ?>" type="hidden">

      <div class="am-cf">
        <input type="submit" name="" value="绑 定" class="am-btn am-btn-primary am-btn-sm am-fl am-btn-block"><!-- 默认按钮不可点击，验证成功后可以点击 -->  
 
      </div>
    </form></div></div>
 <script type="text/javascript">  
    /** 
    * validate(val) 光标离开后触发事件 
    * @param string val 输入的文本 
    * @return string 返回验证是否成功 
    */  
    function validate(val) {  
        var userText = document.getElementById('userText'); // 获取 SPAN 对象  
        // 如果为空或者输入空格执行  
        if (!(val.match(/^\S+$/))) {  
            userText.innerHTML = '<font color="red">请输入会员卡卡号！</font>';  
        } else {  
            if (!(val.match(/^8\d{10}$/))) {  
                userText.innerHTML = '<font color="red">会员卡卡号为11位数字！</font>';  
            } else {  
                var ajax = Ajax(); // 创建 Ajax 对象  
                // 通过 Ajax POST 方法把用户名提交到 validate.php 进行验证用户名是否存在，并返回结果  
                ajax.post('validate.php', {hy_vip:val}, function(data){  
                    userText.innerHTML = data; // Ajax 返回的值显示在 SPAN 标签上    
                });  
            }  
        }  
    }  
</script>  
<?php
}  else{
	$mysqlrow = mysql_fetch_array($result, MYSQL_ASSOC);  
	// echo("mysql数据库查询成功<br>");
  //echo $mysqlrow['hy_vip'];  	//输出绑定会员卡号
  $hy_vip=$mysqlrow['hy_vip'];
if( $conn == false )
{
    die( print_r( sqlsrv_errors(), true));
}
else
{
    //echo("<br>mssql数据库连接成功<br>");
	$rs=sqlsrv_query($conn, "select CardCode,CurrentIntegral from [9002].TBCARD where CardCode='".$hy_vip."'");
if($rs == false)
{
  // echo("数据库连接失败<br>");
}
else
{
    while($row = sqlsrv_fetch_array($rs))
   {
      // print_r($row);
	  echo '<div class="am-g"> <div class="am-u-lg-6 am-u-md-8 am-u-sm-centered"><h1>会员卡积分</h1>    <p>xx广场会员卡积分查询</p></div>  <hr /></div><div class="am-u-sm-11 am-u-sm-centered"> ';

	
	  echo '<button type="button" class="am-btn am-btn-primary am-btn-block">会员卡号'.$row[0].'</button><br>';
	  echo '<button type="button" class="am-btn am-btn-danger am-btn-block">会员积分'.$row[1].'</button></div></div></div>';
    }
    sqlsrv_free_stmt($rs);
    sqlsrv_close($conn);
}
}
}

mysql_close($con);
?>
 <hr>
<div class="am-u-sm-11 am-u-sm-centered"><p>©前端框架Amaze ui.制作：CocaShu.QQ:138029200</p></div>
 
</body>
</html>